clear all
set more off

* set directory 

********************************************************************************
* FIGURE 1 --- TWFE EVENT STUDY

use analysis_file,clear

* sample restrictions
drop if match_units_flag==1
keep if never_ward==1 | ever_treated==1
drop if pop_flag==1
su mean_units_pc, det
drop if mean_units_pc > `r(p95)'

* change treatment variable for easier interpretation after switching to two-year bin
xtset id year
replace after_treatment = 1 if F.after_treatment ==1
	
* switch to two-year bin to improve figure legibility
gen alt_year = year
replace alt_year=floor(alt_year/2)
gen count=1
collapse (sum) count (mean) pc_*  (first) state_year statefips countyfips (max) after_treatment ,by(id alt_year)
xtset id alt_year
tab alt_year

* because the building size of units is reported slightly less frequently than total units, start by running the main specification
* with single-family units.  Then save a sample indicator so that we use exact same sample across specifications that use different 
* building sizes as the outcome

xtevent pc_single if alt_year<1002, ///
	pol(after_treatment) w(-3 3) cluster(statefips)  ///
	reghdfe addabsorb(state_year) note 
	
capture gen in_sample=e(sample)

* create main figure
xtevent pc_all if in_sample==1, ///
	pol(after_treatment) w(-3 3) cluster(statefips)  ///
	reghdfe addabsorb(state_year) note  

xteventplot, levels(95) noprepval nopostpval xlabel(-4 "-8+" -3 "-6" -2 "-4" -1 "-2" 0 "0" 1 "2" 2 "4" 3 "6" 4 "8+") ///
		ytitle(Units/1980 population) xtitle(Years to reform) nominus1label yscale(range(-3 3))  ytick(-3(1)3) ylabel(-3(1)3)
























